package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.commons.util.ReflectUtil;
import net.zigin.nhi.could.waste.annotation.LoginWhitePathAnnotation;
import net.zigin.nhi.could.waste.dto.WasteBoxDto;
import net.zigin.nhi.could.waste.model.WasteBox;
import net.zigin.nhi.could.waste.service.WasteBoxService;

import net.zigin.nhi.could.waste.vo.JsonForResult;
import net.zigin.nhi.could.waste.vo.WasteBoxVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * WasteBox控制器类
 *
 * @author mgw1986
 * @version V1.0
 * @ClassName: WasteBoxController
 * @date 2021-9-13 21:14:43
 */
@Api(tags = "医废箱管理")
@RestController
@RequestMapping("/wasteBox")
public class WasteBoxController extends BaseController {
    @Autowired
    private WasteBoxService wasteBoxService;

    @LoginWhitePathAnnotation
    @GetMapping("/generateQrCode/{id}")
    @ApiOperation("下载二维码")
    @ApiImplicitParam(name = "id", value = "医废id", required = true, dataType = "String")
    public JsonForResult<String> generateQrCode(@PathVariable String id) {
        String content = wasteBoxService.generateQrCode(id);
        return JsonForResult.<String>builder().data(content).success(true).build();
    }

    /**
     * 新增编辑医废箱
     *
     * @param wasteBoxDto 医废箱信息
     * @return 医废箱ID
     */
    @ApiOperation("新增编辑医废箱")
    @ApiImplicitParam(name = "wasteBoxDto", value = "医废箱信息", required = true, dataType = "WasteBoxDto")
    @PostMapping("/save")
    public JsonForResult<String> sava(@RequestBody WasteBoxDto wasteBoxDto) {
        String id = wasteBoxService.saveOrUpdate(wasteBoxDto);
        return JsonForResult.<String>builder().data(id).success(true).build();
    }

    /**
     * 医废箱列表
     *
     * @param wasteBoxDto 医废箱信息
     * @return 医废箱列表
     */
    @ApiOperation("医废箱列表")
    @ApiImplicitParam(name = "wasteBoxDto", value = "医废箱信息", required = true, dataType = "WasteBoxDto")
    @PostMapping("/getList")
    public JsonForResult<List<WasteBoxVo>> getList(@RequestBody WasteBoxDto wasteBoxDto) {
        List<WasteBoxVo> list = wasteBoxService.getList(wasteBoxDto);
        Integer count = wasteBoxService.getCount(wasteBoxDto);
        return JsonForResult.<List<WasteBoxVo>>builder()
                .data(list)
                .total(count)
                .success(true).build();
    }

    /**
     * 医废箱详情
     *
     * @param id ID
     * @return 医废箱详情
     */
    @ApiOperation("医废箱详情")
    @ApiImplicitParam(name = "id", value = "医废箱id", required = true, dataType = "String")
    @GetMapping("/getById/{id}")
    public JsonForResult<WasteBoxVo> getById(@PathVariable String id) {
        WasteBoxVo wasteBoxVo = wasteBoxService.getAllInfoById(id);
        return JsonForResult.<WasteBoxVo>builder().data(wasteBoxVo).success(true).build();
    }

}
